﻿﻿<%@ page language="java" import="java.util.*,com.stone.business.cllyjl.pojo.TClkcmx,com.stone.sys.pojo.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<%
	List<TDictionary> cllbList = (List<TDictionary>)request.getAttribute("cllbList");
	List<TDictionary> clmcList = (List<TDictionary>)request.getAttribute("clmcList");
	List<TDictionary> cldwList = (List<TDictionary>)request.getAttribute("cldwList");
	List<TDictionary> clxhList = (List<TDictionary>)request.getAttribute("clxhList");
	List<TDictionary> ckmcList = (List<TDictionary>)request.getAttribute("ckmcList");
	List<TClkcmx> clkcmxList = (List<TClkcmx>)request.getAttribute("clkcmxList");
 %>
<html>
	<head>	
		<title>材料领用记录</title>
		<script type="text/javascript" src="<%=contextPath%>/js/validator.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/js/jquery.autogrow.js"></script> 
		<script type="text/javascript">
			$(document).ready (function() {
		
			$('textarea').autogrow();		
			});		
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				       {
				            text: '保存',
				            icon:"<%=contextPath%>/images/save.gif",
							 hidden:<%=session.getAttribute("btn_add_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>,
				            handler:function(){
				            	comt();
				            }
				        },'-',
				        {
				            text: '打印',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            	print();
				            },
							 hidden:<%=session.getAttribute("btn_print_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>
		         
				        },'-',
				        {
				            text: '返回',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            	back();
				            }
				        }
			    	]
			    });
			});
			
			function print(){	
               if(document.getElementById("entity.id").value == "0") {
		 	    alert("请先保存该材料入库单");
		 		return false;
		 	}				
			var url="<%=contextPath%>/cllyjl!initRkdDetail.do?directFlag=PRINT_SUCCESS&id=${entity.id}";
			 var win = openSUB(url,2,800,600,50,30);
			}
			function getprojectinfo(){
			window.open("<%=contextPath%>/projectImplement!findByUnitno.do", '统计表格', 'height=800, width=350, top=200, left=300, toolbar=no, menubar=no');
			// document.frmM.action = "<%=contextPath%>/projectImplement!findByUnitno";
			}
			function loadClmc(obj,num) {
			var cllb=obj.value;//alert(cllb);
			var oSelect=document.getElementById("clmc["+num+"]");
			oSelect.options.length=0;
				Ext.Ajax.request({
					method :'POST',
					url :'cllyjl!getClmc.do?cllb='+cllb,
					success : function(response) {
						var clmcList = Ext.decode(response.responseText);
						for(var i=0;i<clmcList.length;i++) {
							var oOption = document.createElement("OPTION");
							oSelect.options.add(oOption);
							oOption.innerText = clmcList[i]["itemName"];
							oOption.value = clmcList[i]["itemId"];
						}
					},
					failure : function() {
						alert("异步失败");
					}
				});
	
			}
			function loadCldw(obj,num) {
			var clmc=obj.value;//alert(clmc);
			var oSelect=document.getElementById("cldw["+num+"]");
			var oXhSelect=document.getElementById("clxh["+num+"]");
			oSelect.options.length=0;
			oXhSelect.options.length=0;
				Ext.Ajax.request({
					method :'POST',
					url :'cllyjl!getCldw.do?clmcPram='+clmc,
					success : function(response) {
						var cldwList = Ext.decode(response.responseText);//alert(cldwList.length);
						for(var i=0;i<cldwList.length;i++) {
							var oOption = document.createElement("OPTION");
							if(cldwList[i]["itemType"]=='CLDW'){
							oSelect.options.add(oOption);
							oOption.innerText = cldwList[i]["itemName"];
							oOption.value = cldwList[i]["itemId"];
							}else{
							oXhSelect.options.add(oOption);
							oOption.innerText = cldwList[i]["itemName"];
							oOption.value = cldwList[i]["itemId"];
							}
						}
					},
					failure : function() {
						alert("异步失败");
					}
				});
	
			}
		</script>
	</head>
  
  <body topmargin="0" >
	<div id = "tbar" style="position:absolute;display:block left:0px; top:0px; width:100%; height:35px; z-index:1;"></div>
	<br>
	<div id="Layer" style="position:absolute;display:block left:0px; top:35px; width:100%; height:94%; z-index:1000; overflow:auto;">
	
		<!-- 信息提示 -->
		<div id="result" align="center"><font color="red">${info }</font></div>
		<table width="100%" height="30">
			<tr>
				<td colspan="4" align="center">
					<span  style="font: 22pt/22pt 宋体;"><strong><b>变电检修工区材料入库单</b></strong></span>
				</td>
			</tr>
			<tr>
				<td colspan="4" align="right">
					入库单编号：${entity.bh}
				
				</td>
			</tr>
		</table>
 		<form id="frmM" class="ct" name="frmM" method="POST" action="<%=contextPath%>/workcardOne!addWorkcardOne.do">
		<input type="hidden" name="searchBean.con6" id="searchBean.con6" value="${searchBean.con6}" >
 			<s:hidden name="entity.dantype" />	
			<input type="hidden" name="entity.bh" value="${entity.bh}"/>	
			<input type="hidden" name="entity.id" id="entity.id" value="${entity.id}"/>
			<input type="hidden" name="entity.rkr" id="entity.rkr" value="${entity.rkr}"/>
			<input type="hidden" name="entity.cly" id="entity.cly" value="${entity.cly}"/>
			<input type="hidden" name="id"  value="${id}"/>
			<table width="100%" border="0" id="infotab">
			<tr>		
			
			<th width="120" nowrap>
						入库人员：
			</th>
			<td>
				<input type="text" style="width:50%" datatype="Require" readonly="true" name="entity.rkrname" value="${entity.rkrname}" msg="审核人必须输入。"/>
				<img style='cursor:pointer' src="<%=contextPath%>/images/editlink.gif" title="" onClick="javascript:getUserselect('entity.rkr','entity.rkrname')" />
						
			</td>
			<th width="120" nowrap>
						材料员：
			</th>
			<td >
				<input type="text" style="width:50%" datatype="Require" readonly="true" name="entity.clyname" value="${entity.clyname}" msg="材料员必须输入。"/>
				<img style='cursor:pointer' src="<%=contextPath%>/images/editlink.gif" title="" onClick="javascript:getUserselect('entity.cly','entity.clyname')" />
			</td>
			<th width="120" nowrap>
					<font color="red">*</font>入库时间：
					</th>
					<td nowrap>
						<input type="text" datatype="Require" onclick="WdatePicker({el:$dp.$('entity.rkdate')})" name="entity.rkdate" readonly="true" value='<fmt:formatDate value="${entity.rkdate}" pattern="yyyy-MM-dd HH:mm"/>' msg="入库时间必须输入。"/>
						<img onclick="WdatePicker({el:$dp.$('entity.rkdate')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					
                         </td>
			</tr>
				
			</table>			
		
			<table width="100%" id="listtab" class = "leadertab" >	

				<tr>
					<th width="30">
					<% if ((session.getAttribute("btn_add_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")))) {%>
					<img src="<%=contextPath%>/images/add.gif" onclick = "setHTML()" style="cursor:pointer"/>
					<%} %>
					</th>
					<th width="30">序号</th>
					<th width="10%">材料类别</th>
					<th width="10%">材料名称</th>
					<th width="120">入库数量</th>					
					<th width="10%">材料单位</th>
					<th width="20%">材料型号</th>
					<th width="120">出厂日期</th>
					<th width="20%">生产厂家</th>
					<th width="10%">仓库名称</th>
					
					
				</tr>
				
				<%if(clkcmxList!=null && clkcmxList.size() > 0){ %>		
				<%for(int i = 0; i < clkcmxList.size(); i++){ %>
				<%  TClkcmx tmp = clkcmxList.get(i); %>		
				<tr id = "tr<%=i %>" class = "repeat">
				<td width="5">
				<% if ((session.getAttribute("btn_add_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")))) {%>
				<img src="<%=contextPath%>/images/delete.gif" onclick = "delrow(this,<%=tmp.getId() %>)" style="cursor:pointer"/>
				<%} %>
				</td>
				<td width="5"><%=i + 1 %></td>
				<td width="10%">
				<select id="cllb[<%=i %>]" name="clkcmxList[<%=i %>].cllb" onchange="loadClmc(this,<%=i %>)">
				<%for(int j = 0; j < cllbList.size(); j++){ %>
				
					<option value="<%=cllbList.get(j).getItemId()%>" <%=tmp.getCllb().equals(cllbList.get(j).getItemId())?"selected":"" %>><%=cllbList.get(j).getItemName()%></option>
				
				<%} %>
				</select>
				</td >	
				<td width="10%">
				<select id="clmc[<%=i %>]" name="clkcmxList[<%=i %>].clmc" onchange="loadCldw(this,<%=i %>)">
				<%for(int j = 0; j < clmcList.size(); j++){ %>
				
					<option value="<%=clmcList.get(j).getItemId()%>" <%=tmp.getClmc().equals(clmcList.get(j).getItemId())?"selected":"" %>><%=clmcList.get(j).getItemName()%></option>
				
				<%} %>
				</select>
				</td width="10%">	
				<td>	
				<input type="text" style="width:30px" datatype="Number" maxlength="3" name="clkcmxList[<%=i %>].lysl" id="clkcmxList[<%=i %>].lysl" value = "<%=tmp.getLysl() %>" msg="领用数量必须输入数字。"/>
				</td>		
				<td width="10%" >
				<select id="cldw[<%=i %>]" name="clkcmxList[<%=i %>].cldw">
				<%for(int j = 0; j < cldwList.size(); j++){ %>
				
					<option value="<%=cldwList.get(j).getItemId()%>" <%=tmp.getCldw().equals(cldwList.get(j).getItemId())?"selected":"" %>><%=cldwList.get(j).getItemName()%></option>
				
				<%} %>
				</select>
				</td >	
				<td width="20%">
				<select id="clxh[<%=i %>]" name="clkcmxList[<%=i %>].clxh" style="width:100%">
				<%for(int j = 0; j < clxhList.size(); j++){ %>
				
					<option value="<%=clxhList.get(j).getItemId()%>" <%=tmp.getClxh().equals(clxhList.get(j).getItemId())?"selected":"" %>><%=clxhList.get(j).getItemName()%></option>
				
				<%} %>
				</select>
				<!--<textarea style="width:100%; height: 25px; min-height: 20px;line-height:15pt" datatype="LimitB" min="0" max="2000" msg="材料型号不能超过2000个字符"  id=clxh[<%=i %>] name="clkcmxList[<%=i %>].clxh" ><%=tmp.getClxh() %></textarea>-->
				</td >	
                  <td  nowrap>
						<input type="text" size="9" datatype="Require" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('clkcmxList[<%=i %>].ccdate')})" name="clkcmxList[<%=i %>].ccdate" readonly="true" value='<fmt:formatDate value="<%=tmp.getCcdate() %>" pattern="yyyy-MM-dd"/>' msg="领用日期必须输入。"/>
						<img onclick="WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('clkcmxList[<%=i %>].ccdate')})" src="<%=contextPath%>/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
					</td>	
               <td width="10%">
				<textarea style="width:100%; height: 25px; min-height: 20px;line-height:15pt" datatype="LimitB" min="0" max="2000" msg="生产厂家不能超过2000个字符"  id=sccj[<%=i %>] name="clkcmxList[<%=i %>].sccj" ><%=tmp.getSccj() %></textarea>
				</td >					
				<td width="10%">
				<select id="ckmc[<%=i %>]" name="clkcmxList[<%=i %>].ckmc">
				<%for(int j = 0; j < ckmcList.size(); j++){ %>
				
					<option value="<%=ckmcList.get(j).getItemId()%>" <%=tmp.getCkmc().equals(ckmcList.get(j).getItemId())?"selected":"" %>><%=ckmcList.get(j).getItemName()%></option>
				
				<%} %>
				</select>
				</td >	
				</tr>
				<%} %>
				<%} %>
				<%
				List<TClkcmx> clkcmx=(List<TClkcmx>)request.getAttribute("clkcmxList");
				
				if(clkcmx!=null&&clkcmx.size()!=0){
				%>
				<input type="hidden" id="manylist" value="<%=clkcmx.size()%>"/>
				<%}else{%>
				<input type="hidden" id="manylist" value="0"/>
				<%}%>
			</table>
			
		
   </form>
   </div>
  </body>
</html>
<script language="javascript">
	function lookImage (imgFile){
		
	    var path = imgFile.value;
	    if(path==""){
			return false;
		    }
	    if( !imgFile.value.match( /.jpg|.gif|.png|.bmp/i ) ){        
	       alert('图片格式错误');        
	       return false;        
	   }
	    if( imgFile.files &&  imgFile.files[0] ){        
	        // Firefox 因安全性问题已无法直接通过 input[file].value 获取完整的文件路径        
	        path = imgFile.files[0].getAsDataURL();            
	    } 
	    //解决IE7，IE8由于安全问题不能获取全路径的问题 
	    var isIE = (document.all) ? true : false;
	    var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
	    var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
	    if(isIE7 || isIE8){
	        imgFile.select();
	        path=document.selection.createRange().text;
	        document.selection.empty();
	    }
	    $('#myImagequ').empty();
	    $('#myImagequ').append("<img id='myImg' src='"+path+"' style='width:400px;height:300px;text-align:center'/>");	   
	    
	    // IE7,IE8 在设置本地图片地址为 img.src 时出现莫名其妙的后果        
	    //（相同环境有时能显示，有时不显示），因此只能用滤镜来解决    
	   
	 }  
	var usernum=parseInt(document.getElementById("manylist").value);
	function getSysdateAndFzr(obj,num){
	var number=parseInt(num);
	if(obj.value!="01"){
		var_wcsj=eval('document.getElementById("oc_wcsj['+number+']")');
		var_wcsj.value='';
		var_fzr=eval('document.getElementById("oc_fzr['+number+']")');	
		var_fzr.value='';						
	return false;
	}
	Ext.Ajax.request({
						method :'POST',
						url :'cllyjl!getSysdateAndFzr.do',						
						success : function(response) {
							//Ext.MessageBox.alert('提示', response.responseText);	
							var data=Ext.decode(response.responseText);
							var_wcsj=eval('document.getElementById("oc_wcsj['+number+']")');
							var_wcsj.value=data.sysdate;
							var_fzr=eval('document.getElementById("oc_fzr['+number+']")');	
							var_fzr.value=data.fzr;							
						},
						failure : function() {
							Ext.MessageBox.alert('提示', '异步失败！');
						}
					});
	}
	// 增加行
	 function setHTML() {
		 var temp0 = "WdatePicker({dateFmt:'yyyy-MM-dd',el:$dp.$('clkcmxList[" + usernum + "].ccdate')})";	
			var str = 	'<tr id = '+ usernum +' class = "repeat">' +
			'<td width="5"><img src="<%=contextPath%>/images/delete.gif" onclick = "delrow(this,0)" style="cursor:pointer"/></td>' + 
			'<td width="5">'+(usernum+1)+'</td>'+
			'<td>'+
			'<select id="cllb['+usernum+']" name="clkcmxList['+usernum+'].cllb" onchange="loadClmc(this,'+usernum+')">' +
			<%for(int i=0; i<cllbList.size();i++){%>
				'<option value="<%=cllbList.get(i).getItemId()%>"><%=cllbList.get(i).getItemName()%></option> ' +
			<%}%> + '</select>'+
			'</td >	'+	
			'<td>'+
			'<select id="clmc['+usernum+']" name="clkcmxList['+usernum+'].clmc" onchange="loadCldw(this,'+usernum+')">' +
			<%for(int i=0; i<clmcList.size();i++){%>
				'<option value="<%=clmcList.get(i).getItemId()%>"><%=clmcList.get(i).getItemName()%></option> ' +
			<%}%> + '</select>'+
			'</td >	'+	
			'<td>'+
			'<input type="text" style="width:30px" datatype="Number" maxlength="3" name="clkcmxList['+usernum+'].lysl" id="clkcmxList['+usernum+'].lysl" value = "" msg="领用数量必须输入数字。"/>'+
			'</td >	'+
			'<td>'+
			'<select id="cldw['+usernum+']" name="clkcmxList['+usernum+'].cldw">' +
			<%for(int i=0; i<cldwList.size();i++){%>
				'<option value="<%=cldwList.get(i).getItemId()%>"><%=cldwList.get(i).getItemName()%></option> ' +
			<%}%> + '</select>'+
			'</td >	'+
			'<td width="20%">'+
			'<select id="clxh['+usernum+']" name="clkcmxList['+usernum+'].clxh">' +
			<%for(int i=0; i<clxhList.size();i++){%>
				'<option value="<%=clxhList.get(i).getItemId()%>"><%=clxhList.get(i).getItemName()%></option> ' +
			<%}%> + '</select>'+
			'</td >	'+	
			'<td><input  onclick="' + temp0 + '" style="width:70" type="text" id=clkcmxList['+ usernum + '].ccdate name=clkcmxList['+ usernum + '].ccdate readonly="true" /></td >' +
            '<td width="20%">'+
			'<textarea style="width:100%; height: 25px; min-height: 20px;line-height:15pt" datatype="LimitB" min="0" max="2000" msg="生产厂家不能超过2000个字符" id=sccj['+usernum+'] name="clkcmxList['+usernum+'].sccj" ></textarea>'+
			'</td >	'+	
		'<td>'+
			'<select id="ckmc['+usernum+']" name="clkcmxList['+usernum+'].ckmc">' +
			<%for(int i=0; i<ckmcList.size();i++){%>
				'<option value="<%=ckmcList.get(i).getItemId()%>"><%=ckmcList.get(i).getItemName()%></option> ' +
			<%}%> + '</select>'+
			'</td >	'+		
			'</tr>';
						
			$('#listtab').append(str);	
					
			usernum++;	
			$('textarea').autogrow();
	}
	//删除班组作业控制卡（一种票）
	function toSeeRwd(id){
		
			if(!isChecked("id")) {
		 		alert("请选择一条记录");
		 		return false;
		 	}
 
		 	id1 = getCheckValue("id");//获取id值
			
		alert(id1);
   
				}

		
		//删除一行（已有数据）
		function delrow(row,id){
	 
	 
			if (confirm("确定要删除该条记录吗？")) {
				if(id != 0) {
					Ext.Ajax.request({
						method :'POST',
						url :'cllyjl!deleteDetail.do?id=' + id,
						params : {},
						success : function(response, options) {
							var obj = Ext.decode(response.responseText);
							Ext.MessageBox.alert('提示', obj["msg"]);
						
		   					$(row).parents(".repeat").remove();	
	 
						},
						failure : function(response, options) {
							Ext.MessageBox.alert('提示 ', '删除失败。');
						}
					});
				} else {
					$(row).parents(".repeat").remove();	
				}
	 
			}
	 
		} 		
	 // 保存
     function comt(){
        if(!Validator.Validate(frmM,1)){
			return false;
		}
     	document.frmM.action = "<%=contextPath%>/cllyjl!saveCllyjl.do?directFlag=RKD_SUCCESS";
     	document.frmM.submit();
     }
     
     // 返回
     function back() {
        /**window.parent.window.location.href = "<%=contextPath%>/jsp/business/cllyjl/listTabBase.jsp?url=cllyjlList!getList.do&searchBean.con20=1&searchBean.con6=2&countPerPage=28&m=m&qxbtn=0";*/
		document.frmM.action = "<%=contextPath%>/cllyjlList!getList.do";
		document.frmM.submit();
     }

</script>
